package com.cn.wanxi.service.impl;


import com.cn.wanxi.dao.ProductDao;
import com.cn.wanxi.dao.impl.ProductImpl;
import com.cn.wanxi.model.ProductModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.service.BaseService;
import com.cn.wanxi.service.ProductService;
import com.cn.wanxi.util.Result;

import java.util.List;

/**
 * 1.给定一个返回前端的固定数据类型ResultModel
 * 2.调用数据实现层
 * 3.得到返回的数据
 * 4.将数据设置到ResultModel这里面
 * 5.返回ResultModel
 */
public class ProductServiceImpl implements ProductService {
    @Override
    public ResultModel findAll(ProductModel productModel) {
//        ResultModel resultModel = new ResultModel();
        ProductDao productDao = new ProductImpl();
        List<ProductModel> list = productDao.findAll(productModel);
//        resultModel.setCode(Result.SUCCESS_CODE);
//        resultModel.setData(list);
//        return resultModel;
        int count=productDao.getCount(productModel);
        return new ResultModel("", 0, count, list);
    }

    @Override
    public ResultModel add(ProductModel model) {
        ProductDao productDao = new ProductImpl();
        int count=productDao.add(model);
        return new ResultModel("",0,count,null);
    }

    @Override
    public ResultModel findById(ProductModel model) {
        return null;
    }

    @Override
    public ResultModel update(ProductModel model) {
        return null;
    }

    @Override
    public ResultModel delete(ProductModel model) {
        return null;
    }

    @Override
    public ResultModel getCount(ProductModel model) {
        return null;
    }

    @Override
    public List<ProductModel> getProductListForHomePage() {
        ProductDao productDao = new ProductImpl();
        return productDao.getProductListForHomePage();
    }

    @Override
    public ResultModel findAllFront(ProductModel productModel) {
        ProductDao productDao = new ProductImpl();
        List<ProductModel> list = productDao.findAllFront(productModel);
//        resultModel.setCode(Result.SUCCESS_CODE);
//        resultModel.setData(list);
//        return resultModel;
        int count=productDao.getCountFront(productModel);
        return new ResultModel("", 0, count, list);
    }

    @Override
    public ResultModel findByIdFront(ProductModel productModel) {
        ProductDao productDao = new ProductImpl();
        List<ProductModel> list = productDao.findByIdFront(productModel);
        return new ResultModel("", 0, 0, list);
    }
}
